home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6190 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  78 lines

  1. Path: news.magicnet.net!usenet
  2. From: gamecox@magicnet.net (Jody Hagins)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Pure Virtual Destructor Question
  5. Date: 11 Feb 1996 01:36:15 GMT
  6. Organization: MagicNet, Inc.
  7. Message-ID: <4fjh6f$8v0@comet2.magicnet.net>
  8. References: <4fas7a$7ns@comet2.magicnet.net> <4fecq0$k4e@news4.digex.net>
  9. NNTP-Posting-Host: pm1-04.magicnet.net
  10. X-Newsreader: WinVN 0.92.6+
  11.  
  12. In article <4fecq0$k4e@news4.digex.net>, ell@access4.digex.net (Ell) says:
  13. >
  14. >Jody Hagins (gamecox@magicnet.magicnet.net) wrote:
  15. >: Assume a class Foo s.t.
  16. >: 
  17. >: class Foo
  18. >: {
  19. >: public:
  20. >:   virtual ~Foo() = 0;
  21. >: };
  22. >: 
  23. >: inline Foo::~Foo()
  24. >: {
  25. >:   // do some destructor stuff
  26. >: }
  27. >
  28. >Immediately above you are logically "defining" your "pure virtual" 
  29. >destructor "inside the class where it is "declared" as a pure virtual
  30. >function.  It is _illegal_ to logically, or physically "define" a pure
  31. >virtual function in the class it is "declared" in.  A pure virtual should
  32. >only be defined in classes derived from the class where the pure virtual
  33. >is declared.  Only derived classes should "do some destructor stuff".
  34.  
  35.  
  36. No, that's not correct.  I've received several replies with this same
  37. comment, so I'll give the appropriate response.  First, thanks for
  38. replying, it's what makes this group great.  There's always tons of
  39. peolpe willing to help.
  40.  
  41. Now, for the pure virtual function lesson.  If you don't want my
  42. version, look in Meyers' Effective C++, item 36.
  43.  
  44. A pure virtual function *can* have default behavior.  For example,
  45.  
  46. class Foo
  47. {
  48. public:
  49.   virtual void Bar() = 0;
  50. };
  51.  
  52. void Foo::Bar()
  53. {
  54.   cout "Foo::Bar() default function called" << endl;
  55. }
  56.  
  57. is perfectly legal, and I get this to work with no problem.  However,
  58. the problem comes in if you try to "automatic inline" the function with
  59. the class declaration.  Then, I get compiler errors, and that's what I
  60. believe I should be able to do.
  61.  
  62. I've received on response indicating that the following works fine on
  63. his compiler...
  64.  
  65.  
  66. class Foo
  67. {
  68. public:
  69.   virtual ~Foo() = 0 { }
  70. };
  71.  
  72.  
  73. However, mine (based on at&t cfront 3.0) barfs on it.
  74.  
  75. Thanks,
  76.     -Jody
  77.  
  78.